package algorithm.graph.adjacencymatrix;

import java.util.*;

import algorithm.graph.base.Edge;

public class AdjacencyMatrixGraph {
    private final int nodeCount;
    private final int[][] graphData;


    public static Edge edge(int from, int to, int weight) {
        return new Edge(from, to, weight);
    }

    public static Edge edge(int from, int to) {
        return new Edge(from, to, 1);
    }


    public AdjacencyMatrixGraph(int nodeCount) {
        this.nodeCount = nodeCount;
        this.graphData = new int[nodeCount][nodeCount];
        for (int i = 0; i < this.graphData.length; i++) {
            Arrays.fill(graphData[i], -1);
        }
    }

    public void initNonDirectedGraphEdges(List<Edge> edgeList) {
        edgeList.forEach(it -> {
            graphData[it.from()][it.to()] = it.weight();
            graphData[it.to()][it.from()] = it.weight();
        });
    }

    public void initDirectedGraphEdges(List<Edge> edgeList) {
        edgeList.forEach(it -> {
            graphData[it.from()][it.to()] = it.weight();
        });
    }

    public int getNodeCount() {
        return nodeCount;
    }

    public int[][] getGraphData() {
        return graphData;
    }
}
